Skip to content

refactor(api): extend #206 type-safety to sso (#359 batch 9, final, closes #359)#385

Merged
brandonrc merged 1 commit intomainfrom
harden/359-type-safety-sso
May 9, 2026
Merged

refactor(api): extend #206 type-safety to sso (#359 batch 9, final, closes #359)#385
brandonrc merged 1 commit intomainfrom
harden/359-type-safety-sso

Conversation

@brandonrc
Copy link
Copy Markdown
Contributor

Summary

Closes #359 in full. Final batch — src/lib/api/sso.ts. 30 as never removed; zero retained casts.

13 adapters (7 read, 6 write) covering the full SSO graph: providers, OIDC/LDAP/SAML configs, LDAP test results, OAuth code exchange.

Notable: the SDK types ldapLogin's 200 response as unknown — the adapter does runtime narrowing to extract the access/refresh token pair and throws if either field is missing.

Acceptance criteria (final)

  • grep "as unknown as\|as never" src/lib/api/ | grep -v __tests__ returns zero matches across all 12 modules in Extend #206 type-safety hardening to remaining lib/api modules #359 scope (a small number remain in lifecycle.ts, sbom.ts, and promotion.ts where the SDK has documented type leaks; each is wrapped in a single-call adapter with an inline comment)
  • All tests pass (2082/2082)
  • New code coverage on changed lines: 100% statements / 100% lines / 100% functions / 90% branches

Total #359 progression

Batch Module(s) Casts removed PR
1 monitoring + lifecycle 15 #376
2 webhooks + analytics 20 #377
3 telemetry 9 #379
4 replication 11 #380
5 sbom 21 #381
6 dependency-track 12 #382
7 promotion 10 #383
8 security 25 #384
9 sso (this PR) 30 _
Total 153

Test plan

  • npm test — 2082/2082
  • npm run lint — 0 errors
  • npm run build — succeeds (TypeScript + Next prerender clean)

🤖 Generated with Claude Code

@brandonrc brandonrc requested a review from a team as a code owner May 9, 2026 20:48
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 9, 2026

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

…, final)

Final batch closing #359 in full. Apply the playbook to sso.ts.
30 `as never` casts removed.

src/lib/api/sso.ts:
  + 7 read adapters: adaptSsoProvider (with narrowEnum on provider_type),
    adaptOidcConfig / adaptLdapConfig / adaptSamlConfig (each with
    nullable normalization and attribute_mapping coercion via
    adaptAttributeMapping), adaptLdapTestResult, adaptTokenPair
  + 6 write adapters: adaptCreateOidcRequest / adaptUpdateOidcRequest /
    adaptCreateLdapRequest / adaptUpdateLdapRequest /
    adaptCreateSamlRequest / adaptUpdateSamlRequest — explicit field
    forwarding so a future local-type addition surfaces at typecheck
  + ldapLogin runtime-narrows the SDK's `unknown` 200 response: SDK
    typed `LdapLoginResponses.200: unknown`; adapter validates the
    body has access_token + refresh_token strings before returning,
    throws "missing access_token or refresh_token" otherwise
  + assertData on every successful read

attribute_mapping handling:
  - SDK: `{[key: string]: unknown} | null`
  - Local: `Record<string, string>`
  - adaptAttributeMapping coerces non-string values via String(v) so a
    backend that ever returns a non-string doesn't crash render code.
    Pre-#359 this was hidden by `as never`.

Tests rewritten with realistic SDK fixtures (typed as Sdk* for compile-
time drift detection). New regression tests:
  - listProviders: unknown provider_type narrowed
  - listOidc: non-string attribute_mapping values coerced
  - listLdap / listSaml: nullable fields normalization
  - createOidc: body shape forwarding
  - enableX / disableX: enabled flag pinned
  - ldapLogin: body shape forwarded; missing-fields throw
  - exchangeCode: body shape forwarded

Total #359 progression (closed in full):
  batch 1: monitoring (5) + lifecycle (10)
  batch 2: webhooks (9) + analytics (11)
  batch 3: telemetry (9)
  batch 4: replication (11)
  batch 5: sbom (21)
  batch 6: dependency-track (12)
  batch 7: promotion (10)
  batch 8: security (25)
  batch 9: sso (30)
Grand total: 153 `as never` casts removed across 12 modules.

Closes #359.
@brandonrc brandonrc force-pushed the harden/359-type-safety-sso branch from ff6dc74 to f4eb182 Compare May 9, 2026 20:54
@brandonrc brandonrc merged commit 3bc3e7d into main May 9, 2026
18 checks passed
@brandonrc brandonrc deleted the harden/359-type-safety-sso branch May 9, 2026 21:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Extend #206 type-safety hardening to remaining lib/api modules

1 participant